---
created:
  source_filename: /home/runner/work/mknodes/mknodes/src/mknodes/manual/navs_section.py
  source_function: _
  source_line_no: 45
hide:
- toc
icon: material/call-split
title: Using decorators
---

## Code for this section

``` {.py  title='routing.py' linenums='1'}
"""MkNodes routing example.

MkNodes also supports setting up Navs via decorators.
"""

import mknodes as mk


NAV_TEXT = """You can also use decorators to attach MkNavs. These navs then can continue
to build the tree without using decorators (by adding sub-navs).
"""

nav = mk.MkNav("Using decorators")


@nav.route.page("Routed page")
def routed_page(page: mk.MkPage) -> None:
    """Builds a MkPage and attaches it to the router MkNav."""
    page += mk.MkAdmonition("I'm a page added via decorators!")


@nav.route.page("Routed", "Deeply", "Nested", "Nested page")
def routed_nested_page(page: mk.MkPage) -> None:
    """Builds a nested MkPage and attaches it to the router MkNav."""
    page += mk.MkAdmonition("I'm a nested page added via decorators!")


@nav.route.nav("Routed", "Deeply", "Nested", "Nav")
def routed_nav(nav: mk.MkNav) -> None:
    """Builds a nested MkNav and attaches it to the router MkNav."""
    index_page = nav.add_page(is_index=True)
    index_page += mk.MkAdmonition(NAV_TEXT)
    page = nav.add_page("Routed section page")
    page += mk.MkAdmonition("Routed section page content")

```

## MkNav.route Docstrings

::: mknodes.navs.navrouter.NavRouter
